From 1a35097a9a4b433059614d14843b1b7fb266f2b6 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 31 Jul 2014 12:18:09 -0700 Subject: [PATCH] Use sources from the lockfile The sources in the lock file contain precise information about git deps so we want them over the non-precise versions in the source. --- src/cargo/core/registry.rs | 22 ++++++++-------------- src/cargo/ops/cargo_compile.rs | 11 ++++++++--- src/cargo/ops/cargo_generate_lockfile.rs | 5 ++--- tests/test_cargo_compile_git_deps.rs | 21 +++++++++++++++------ 4 files changed, 33 insertions(+), 26 deletions(-) diff --git a/src/cargo/core/registry.rs b/src/cargo/core/registry.rs index 22b6beefb..d737d429f 100644 --- a/src/cargo/core/registry.rs +++ b/src/cargo/core/registry.rs @@ -22,20 +22,7 @@ pub struct PackageRegistry<'a> { } impl<'a> PackageRegistry<'a> { - pub fn new<'a>(source_ids: Vec, - config: &'a mut Config<'a>) -> CargoResult> { - - let mut reg = PackageRegistry::empty(config); - let source_ids = dedup(source_ids); - - for id in source_ids.iter() { - try!(reg.load(id, false)); - } - - Ok(reg) - } - - fn empty<'a>(config: &'a mut Config<'a>) -> PackageRegistry<'a> { + pub fn new<'a>(config: &'a mut Config<'a>) -> PackageRegistry<'a> { PackageRegistry { sources: SourceMap::new(), overrides: vec!(), @@ -77,6 +64,13 @@ impl<'a> PackageRegistry<'a> { Ok(()) } + pub fn add_sources(&mut self, ids: Vec) -> CargoResult<()> { + for id in dedup(ids).iter() { + try!(self.load(id, false)); + } + Ok(()) + } + pub fn add_overrides(&mut self, ids: Vec) -> CargoResult<()> { for id in ids.iter() { try!(self.load(id, true)); diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index 953570ac6..96182344b 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -65,7 +65,6 @@ pub fn compile(manifest_path: &Path, let user_configs = try!(config::all_configs(os::getcwd())); let override_ids = try!(source_ids_from_config(&user_configs, manifest_path.dir_path())); - let source_ids = package.get_source_ids(); let (packages, resolve, resolve_with_overrides, sources) = { let lockfile = manifest_path.dir_path().join("Cargo.lock"); @@ -73,11 +72,17 @@ pub fn compile(manifest_path: &Path, let mut config = try!(Config::new(*shell, update, jobs, target.clone())); - let mut registry = try!(PackageRegistry::new(source_ids, &mut config)); + let mut registry = PackageRegistry::new(&mut config); let resolved = match try!(load_lockfile(&lockfile, source_id)) { - Some(r) => r, + Some(r) => { + try!(registry.add_sources(r.iter().map(|p| { + p.get_source_id().clone() + }).collect())); + r + } None => { + try!(registry.add_sources(package.get_source_ids())); try!(resolver::resolve(package.get_package_id(), package.get_dependencies(), &mut registry)) diff --git a/src/cargo/ops/cargo_generate_lockfile.rs b/src/cargo/ops/cargo_generate_lockfile.rs index 03209af7c..b792dea5f 100644 --- a/src/cargo/ops/cargo_generate_lockfile.rs +++ b/src/cargo/ops/cargo_generate_lockfile.rs @@ -28,9 +28,8 @@ pub fn generate_lockfile(manifest_path: &Path, let resolve = { let mut config = try!(Config::new(shell, update, None, None)); - let mut registry = - try!(PackageRegistry::new(source_ids, &mut config)); - + let mut registry = PackageRegistry::new(&mut config); + try!(registry.add_sources(source_ids)); try!(resolver::resolve(package.get_package_id(), package.get_dependencies(), &mut registry)) diff --git a/tests/test_cargo_compile_git_deps.rs b/tests/test_cargo_compile_git_deps.rs index 40cf66815..060bfdf0e 100644 --- a/tests/test_cargo_compile_git_deps.rs +++ b/tests/test_cargo_compile_git_deps.rs @@ -1,5 +1,4 @@ -use std::io::File; -use std::path; +use std::io::{fs, File}; use support::{ProjectBuilder, ResultTest, project, execs, main_file, paths}; use support::{cargo_dir}; @@ -553,14 +552,24 @@ test!(recompilation { FRESH, git_project.root().display(), FRESH, p.root().display()))); - // Commit the changes and make sure we trigger a recompile - File::create(&git_project.root().join("src/bar.rs")).write_str(r#" - pub fn bar() { println!("hello!"); } - "#).assert(); + // Commit the changes and make sure we don't trigger a recompile because the + // lockfile says not to change git_project.process("git").args(["add", "."]).exec_with_output().assert(); git_project.process("git").args(["commit", "-m", "test"]).exec_with_output() .assert(); + assert_that(p.process(cargo_dir().join("cargo-build")).arg("-u"), + execs().with_stdout(format!("{} git repository `file:{}`\n\ + {} bar v0.5.0 (file:{}#[..])\n\ + {} foo v0.5.0 (file:{})\n", + UPDATING, git_project.root().display(), + FRESH, git_project.root().display(), + FRESH, p.root().display()))); + + println!("one last time"); + + // Remove the lockfile and make sure that we update + fs::unlink(&p.root().join("Cargo.lock")).assert(); assert_that(p.process(cargo_dir().join("cargo-build")).arg("-u"), execs().with_stdout(format!("{} git repository `file:{}`\n\ {} bar v0.5.0 (file:{}#[..])\n\ -- 2.30.2